#include "../mqserver/mq_binding.hpp"
#include "gtest/gtest.h"
#include <iostream>

mymq::BindingManager::Ptr bmp;

class BindingTest : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        bmp = std::make_shared<mymq::BindingManager>("./data/meta.db");
    }
    virtual void TearDown() override
    {
        //emp->clear();
        std::cout << "最后的清理！！\n";
    }
};

// TEST(binding_test,insert_test)
// {
//     bmp->Bind("exchange1","queue1","music.pop.*",true);
//     bmp->Bind("exchange1","queue2","music.hh.*",true);
//     bmp->Bind("exchange1","queue3","music.jdj.*",true);
//     bmp->Bind("exchange2","queue3","music.jdj.*",true);
//     bmp->Bind("exchange2","queue1","music.pop.*",true);
//     bmp->Bind("exchange2","queue2","music.hh.*",true);
//     ASSERT_EQ(bmp->size(),6);
// }
TEST(queue_test, select_test) {
    ASSERT_EQ(bmp->exists("exchange1", "queue1"), true);
    ASSERT_EQ(bmp->exists("exchange1", "queue2"), true);
    ASSERT_EQ(bmp->exists("exchange1", "queue3"), true);
    ASSERT_EQ(bmp->exists("exchange2", "queue1"), true);
    ASSERT_EQ(bmp->exists("exchange2", "queue2"), true);
    ASSERT_EQ(bmp->exists("exchange2", "queue3"), true);

    mymq::Binding::Ptr bp = bmp->getBinding("exchange2", "queue2");
    ASSERT_NE(bp.get(), nullptr);
    ASSERT_EQ(bp->exchange_name, std::string("exchange2"));
    ASSERT_EQ(bp->queue_name, std::string("queue2"));
    ASSERT_EQ(bp->binding_key, std::string("music.hh.*"));
}

// TEST(queue_test, select_exchange_test) {
//     mymq::QueueBindingMap mqbm = bmp->getExchangeBindings("exchange1");
//     ASSERT_EQ(mqbm.size(), 3);
//     ASSERT_NE(mqbm.find("queue1"), mqbm.end());
//     ASSERT_NE(mqbm.find("queue2"), mqbm.end());
//     ASSERT_NE(mqbm.find("queue3"), mqbm.end());
// }
// TEST(queue_test, remove_queue_test) {
//     bmp->removeMsgQueueBindings("queue1");
//     ASSERT_EQ(bmp->exists("exchange1", "queue1"), false);
//     ASSERT_EQ(bmp->exists("exchange2", "queue1"), false);
// }
// TEST(queue_test, remove_exchange_test) {
//     bmp->removeExchangeBindings("exchange1");
//     ASSERT_EQ(bmp->exists("exchange1", "queue1"), false);
//     ASSERT_EQ(bmp->exists("exchange1", "queue2"), false);
//     ASSERT_EQ(bmp->exists("exchange1", "queue3"), false);
// }
// TEST(queue_test, remove_single_test) {
//     ASSERT_EQ(bmp->exists("exchange2", "queue3"), true);
//     bmp->unBind("exchange2", "queue2");
//     ASSERT_EQ(bmp->exists("exchange2", "queue3"), false);
//     //ASSERT_EQ(bmp->exists("exchange2", "queue3"), true);
// }

int main(int argc,char* argv[])
{
    testing::AddGlobalTestEnvironment(new BindingTest);
    testing::InitGoogleTest();
    return RUN_ALL_TESTS();
}

